/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.upn.sigemfi.can.bc;

import edu.upn.sigemfi.can.be.TransaccionExternaWeb;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;



/**
 *
 * @author Programador
 */
public class TransaccionExternaWebDelegate {

    private TransaccionExternaWebFacadeLocal local;

    public TransaccionExternaWebDelegate(){
        local=lookupTransaccionExternaWebFacade();
    }

    public void crear(TransaccionExternaWeb transaccionExternaWeb) throws Exception{
        try {
            local.create(transaccionExternaWeb);
        } catch (Exception e) {
            local=lookupTransaccionExternaWebFacade();
            throw new Exception("Crear Tipo de Transaccion Web Externa" + e.getMessage(), e);
        }
    }

    public void editar(TransaccionExternaWeb transaccionExternaWeb) throws Exception{
        try {
            local.edit(transaccionExternaWeb);
        } catch (Exception e) {
            local=lookupTransaccionExternaWebFacade();
            throw new Exception("Editar Transaccion Web Externa" + e.getMessage(), e);
        }
    }

    public void eliminar(TransaccionExternaWeb transaccionExternaWeb) throws Exception{
        try {
            local.remove(transaccionExternaWeb);
        } catch (Exception e) {
            local=lookupTransaccionExternaWebFacade();
            throw new Exception("Eliminar Transaccion Web Externa" + e.getMessage(), e);
        }
    }

    public TransaccionExternaWeb buscar(long codigo) throws Exception{
        try {
            return local.find(codigo);
        } catch (Exception e) {
            local=lookupTransaccionExternaWebFacade();
            throw new Exception("Buscar Transaccion Web Externa" + e.getMessage(), e);
        }
    }

    public List<TransaccionExternaWeb> listar() throws Exception {
        try {
            return local.findAll();
        } catch (Exception e) {
            local = lookupTransaccionExternaWebFacade();
            throw new Exception("Listar Transaccion Web Externa. " + e.getMessage(), e);
        }
    }

    private TransaccionExternaWebFacadeLocal lookupTransaccionExternaWebFacade() {
        try {
            Context c = new InitialContext();
            return (TransaccionExternaWebFacadeLocal) c.lookup("java:comp/env/TransaccionExternaWebFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }



}
